#!/bin/bash

ex() {
    rm -f "test file" "temp file"
    exit ${1:-1}
}

cp test.001.in "test file"

./mark2html -i "test file" -o "temp file"
if ! diff -Nua "test.001.out" "temp file" &>/dev/null; then
    echo "Presentation error" >&2
    ex
fi

cat "test file" | ./mark2html -i - -o "temp file"
if ! diff -Nua "test.001.out" "temp file" &>/dev/null; then
    echo "Presentation error" >&2
    ex
fi

cat "test file" | ./mark2html -i - -o - > "temp file" 
if ! diff -Nua "test.001.out" "temp file" &>/dev/null; then
    echo "Presentation error" >&2
    ex
fi

cat "test file" | ./mark2html > "temp file" 
if ! diff -Nua "test.001.out" "temp file" &>/dev/null; then
    echo "Presentation error" >&2
    ex
fi

for a in test.*.in
do
    ./mark2html -i "$a" -o "temp file"
    if ! diff -Nua "${a%.*}.out" "temp file"; then
        echo "Wrong answer, test \`$a'" >&2
        ex
    fi
done

echo "Accepted"
ex 0
